package com.hedl.classroom.controller;

import com.hedl.classroom.base.exception.CommonResult;
import com.hedl.classroom.model.po.CourseTeacher;
import com.hedl.classroom.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 老师相关接口
 */
@Slf4j
@RestController
@Api(value = "老师相关接口",tags = {"老师相关接口"})
public class CourseTeacherController {

    @Resource
    private CourseTeacherService courseTeacherService;

    @GetMapping("/courseTeacher/list/{courseId}")
    @ApiOperation("根据课程id查询任课老师")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId",value = "课程id",required = true,dataType = "Long")
    })
    public List<CourseTeacher> queryCourseTeacher(@PathVariable("courseId") Long courseId){
        List<CourseTeacher> courseTeachers = courseTeacherService.queryCourseTeacher(courseId);
        return courseTeachers;
    }

    @PostMapping("/courseTeacher")
    @ApiOperation("新增/修改 任课老师")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseTeacher",value = "新增/修改任课老师基本信息",required = true,dataType = "Object")
    })
    public CourseTeacher saveCourseTeacher(@RequestBody CourseTeacher courseTeacher){
        CourseTeacher courseTeacher1 = courseTeacherService.saveCourseTeacher(courseTeacher);
        return courseTeacher1;
    }

    @DeleteMapping("/courseTeacher/course/{courseId}/{teacherId}")
    @ApiOperation("删除任课老师")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId",value = "课程id",required = true,dataType = "Long"),
            @ApiImplicitParam(name = "teacherId",value = "老师id",required = true,dataType = "Long")
    })
    public CommonResult deleteTeacher(@PathVariable("courseId") Long courseId,@PathVariable("teacherId") Long teacherId){
        return courseTeacherService.deleteTeacher(courseId,teacherId);
    }
}
